import AppAxios from "./http"
import AppUseAxios from "./useAxios"
import { API_BASE_URL, TIME_OUT } from "./config"
import type {AxiosRequestConfig} from 'axios'
import {UseAxiosOptions} from '@vueuse/integrations/useAxios'

const http = new AppAxios({
  baseURL: API_BASE_URL,
  timeout: TIME_OUT
})

/**
 * 该函数必须在 setup 中进行使用
 */ 
export const useAxios = (url: string, axiosOptions?: AxiosRequestConfig, useAxiosOptions?: UseAxiosOptions) => AppUseAxios(
  url,
  { baseURL: API_BASE_URL, timeout: TIME_OUT, ...axiosOptions },
  // Will automatically run axios request when `useAxios` is used
  { immediate: true, ...useAxiosOptions }
)

export default http
